<<style>

</style>

<template>
    <div class="table">
        <!-- 头部菜单按钮 -->
        <div class="table-header">
             <Row>
                <Col span="12">
                    <Button type="success" icon="android-add" @click="showAddModal">添加常见问题</Button>
                </Col>
                <Col span="12">
                    <div style="float:right;"> 
                        <Input v-model="keywords" placeholder="请输入..." style="width: 150px"></Input>
                        <Button type="ghost" icon="ios-search">搜索</Button>
                    </div>
                </Col>
            </Row>
        </div>
        <Table border :columns="columns" :data="list"></Table>
        <Page :current.sync="page" :total="total_count" :page-size="limit" @on-change="getList"  show-total show-elevator :style="{'text-align': 'center'}"></Page>

        <Modal v-model="showAdd" title="添加常见问题" width="600px" :mask-closable="false" :styles="{top: '30px'}">
	        <add ref="addModal" @closeAdd="closeAddModal" ></add>
            <div slot="footer"></div>
	    </Modal>
        <Modal v-model="showEdit" title="编辑常见问题" width="600px" :mask-closable="false" :styles="{top: '30px'}">
	        <edit ref="editModal" @closeEdit="closeEditModal"></edit>
            <div slot="footer"></div>
	    </Modal>
    </div>
</template>

<script>
import http from '../../../libs/http';
import add from './add';
import edit from './edit';
export default {
    components: {
        add,
        edit
    },
    data () {
        return {
            showAdd: false,
            showEdit:false,
            list: [],
            page: 1,
            limit: 15,
            total_count: 0,
            keywords: '',
            columns: [
                { title: 'ID', key: 'id', align: 'center', width:'10%' },
                { title: '问题', key: 'question', align: 'center' },
                { title: '回答', key: 'answer', align: 'center' },
                { title: '排序值', key: 'listorder', align: 'center', width: '7%'},
                { title: '创建时间', key: 'create_time', align: 'center', width:'15%' },
                { title: '修改时间',key: 'update_time', align: 'center', width:'15%' },
                {
                    title: '操作',
                    key: 'action',
                    align: 'center',
                    width: '15%',
                    render: (h, param) => {
                        return h('div', [
                            h('Button',{
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '10px'
                                },
                                on: {
                                    click: () => {
                                        this.edit(param.row.id)
                                    }
                                }
                            }, '编辑'),
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                on: {
                                    click: () => {
                                        this.remove(param.row.id)
                                    }
                                }
                            }, '删除')
                        ])
                    }
                }
            ]
        }
    },
    methods: {
        getList( page ) {  //获取FAQ列表
            this.page = page;
            var that = this;
            var url = 'admin/help/index/page/' + page + '/limit/' + this.limit;
            this.apiGet(url).then((res) => {
                if (res.code != 200) {
                    this.handleError(res);
                } else {
                    that.list = res.data.list;
                    that.total_count = res.data.total_count;
                }
            })
        },
        showAddModal () {
            this.showAdd = true;
        },
        edit( id ) {  //编辑按钮
            this.showEdit = true;
            this.$refs.editModal.getInfo(id);
        },
        remove(id) {  //删除按钮弹窗
            this.$Modal.confirm({
                    width: "200",
                    content: '确认是否删除',
                    onOk: () => {
                        this.delete(id);
                    }
                });
        },
        delete(id) {  //删除方法
            var url = 'admin/help/delete/'
            this.apiDelete(url, id).then((res) => {
                if (res.code != 200) {
                    this.handleError(res);
                } else {
                    this.getList(this.page);
                    this.$Message.success(res.msg);
                    
                }
            });
        },
        closeAddModal() {  //关闭添加模态框
            this.showAdd = false;
            this.getList(this.page);
        },
        closeEditModal () {  //关闭编辑模态框
            this.showEdit = false
            this.getList(this.page)
        }
    },
    created () {
        this.getList(this.page);
    },
    watch: {
        showarticle: function(status) {
            if (status == false) {
                this.$refs.addModal.handle
            }
        }
    },
    mixins: [http]
    
}
</script>